package control;

import java.util.ArrayList;
import model.Game;
import model.Player;

/**
 *
 * @author Dustin
 */
public class GameServer {
    private static GameServer uniqueInstance = null;

    private Database database;
    private ArrayList<Game> games = new ArrayList<Game>();
    private ArrayList<Player> players = new ArrayList<Player>();

    public GameServer() {
        database = new Database();
        addGame(new Game("Eenendertigen"));
    }

    public static synchronized GameServer getInstance() {
        return uniqueInstance == null ? uniqueInstance = new GameServer() : uniqueInstance;
    }

    public Game getGame(String tableName) {
        Game g = null;
        for(int i = 0; i < games.size() && g == null; i++) {
            if(games.get(i).getTable().getName().equals(tableName)) {
                g = games.get(i);
            }
        }
        return g;
    }

    public ArrayList<Game> getGames() {
        return games;
    }

    public Database getDatabase() {
        return database;
    }

    public void addGame(Game aGame) {
        games.add(aGame);
    }

    public void addPlayer(Player aPlayer) {
        players.add(aPlayer);
    }

    public void removeGame(Game aGame) {
        games.remove(aGame);
    }

    public void removePlayer(Player aPlayer) {
        players.remove(aPlayer);
    }
}
